<?php
	include_once "../classes/module_bs.php";
	include_once "../classes/thuvienham.php";
	
	if(!IsAdmin())
		header("Location: index.php");
	$MaModule = $_GET['id'];
	$PIN      = $_GET['pin'];
	
	$module = new module_bs();
	$module->SetMaModule($MaModule);
	$module_data = $module->LayDanhSach();
	
	if($module_data[0]['MaModule'] == $MaModule && $module_data[0]['PIN'] == $PIN)
	{	
		$tmp = ($module_data[0]['TrangThai'] == 1) ? 0 : 1;
		
		$module->SetTrangThai($tmp);
		$kq = $module->CapNhatTrangThai();
		
		$module->SetPIN(GeneratePIN());
		$module->CapNhatPIN();
	}
	else
	{
		$module->SetPIN(GeneratePIN());
		$module->CapNhatPIN();
	}
	
	QuayVeTrangTruoc();
?>